{% extends '../layout.html' %}
{% block main %}
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    {% if add_btn %}
        <div>
            {{ add_btn|safe }}
        </div>
    {% endif %}
    <table lay-filter="list">
        <thead>
        <tr>
            {% for item in header_list %}
                <th lay-data="{field: '{{ item }}'}">
                    {{ item }}
                </th>
            {% endfor %}
        </tr>
        </thead>
        <tbody>
        {% for row in body_list %}
            <tr>
                {% for item in row %}
                    <td>{{ item }}</td>
                {% endfor %}
            </tr>
        {% endfor %}
        </tbody>
    </table>
    <div id="pager" style="text-align: center"></div>
{% endblock %}
{% block footer %}
    <script>
        var table = layui.table;
        var laypage = layui.laypage;
        //转换静态表格
        table.init('list');
        laypage.render({
            elem: 'pager'
            , count: {{pager.count}} //数据总数，从服务端得到
            , curr: {{ pager.curr }}
            , limit: {{ pager.limit }}
            , layout: ['count', 'prev', 'page', 'next', 'skip']
            , jump: function (obj, first) {
                //首次不执行
                if (!first) {
                    var search = location.search.replace(/page=(\d+)/g, 'page=' + obj.curr)
                    var url = `{{ base_url }}` + (search ? search : ('?page=' + obj.curr))
                    location.href = url
                }
            }
        });
    </script>
{% endblock %}